package com.itaming.lycheeframework.mybatisplus.id;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.itaming.lycheeframework.support.id.SnowflakeIdGenerator;

import java.net.InetAddress;

/**
 * 自定义ID生成器
 *
 * @author A.Ming
 */
public class LycheeIdGenerator implements IdentifierGenerator {

    /**
     * 框架统一雪花算法ID生成器
     */
    private final SnowflakeIdGenerator generator;

    /**
     * 自定义ID生成器
     */
    public LycheeIdGenerator() {
        this.generator = new SnowflakeIdGenerator();
    }

    /**
     * 自定义ID生成器
     */
    public LycheeIdGenerator(InetAddress inetAddress) {
        this.generator = new SnowflakeIdGenerator(inetAddress);
    }

    /**
     * 自定义ID生成器
     */
    public LycheeIdGenerator(long workerId, long datacenterId) {
        this.generator = new SnowflakeIdGenerator(workerId, datacenterId);
    }

    /**
     * 生成ID
     *
     * @param entity 实体
     * @return ID
     */
    @Override
    public Number nextId(Object entity) {
        return generator.nextId();
    }

}
